import Vue from 'vue';
import { Toast } from 'vant';
Vue.use(Toast);
import store from '../store';

const errorHandle = err => {
  switch (err.response.status) {
    case 401:
      Toast({
        message: '401 (Token has expired)',
        duration: 1500,
        onClose: () => {
          store.commit('toLogin');
        }
      });
      break;
    case 404:
      Toast('404 (Not Found)');
      break;
    case 500:
      Toast('500 (Internal Server Error)');
      break;
    case 502:
      Toast('502 (Bad Gateway)');
      break;
    default:
      Toast('Unknown Error');
  }
};

export default errorHandle;
